#include <REGX52.H>
#include "Delay.h"
#include "Timer0.h"
#include "Key.h"
#include "NiXie.h"

//sbit LED=P2^0; //sbit不是C语言的标准类型，C51扩展的类型，^这个符号也不是异或，C51特有的声明方式
sbit Motor=P1^0; //电机

unsigned char Counter, Compare;
unsigned int KeyNum, Speed;

void Delay1(unsigned int i){
	unsigned int k=i;
	while(i--);
	while(k--);
}




void main(void){
	unsigned char Time, i;
	Timer0Init();
	Compare=5;
	Motor=0;// 默认电机不转
	while(1) {
		KeyNum = Key();
		if(KeyNum == 1){
			Speed++;
			Speed%=4; // if(x>4) x=0;
			
			if(Speed == 0) {
				Compare = 0;
			} else if(Speed == 1) {
				Compare=50;
			}else if(Speed == 2) {
				Compare=75;
			}else if(Speed == 3) {
				Compare = 100;
			}
		}
		Nixie(1, Speed);
	}
}


/*定时器中断函数模板*/
void Timer0_Routine() interrupt 1
{
	TL0 = 0x9C;		//设置定时初值
	TH0 = 0xFF;		//设置定时初值
	Counter++;
	Counter%=100;  //if >100, counter=0
	if(Counter < Compare){
		//LED=0;
		Motor=1;  //电机转 高电平触发
	} else {
		//LED=1;
		Motor=0;
	}
}
